<template>
  <view v-if="shenheStatus == 0" class="add-card">
    <view class="form-section">
      <u-form
        :model="form"
        ref="uForm"
        labelAlign="center"
        :borderBottom="true"
        label-width="160rpx"
      >
        <u-form-item :label="$t('user.cardAcc')">
          <u-input v-model="form.account" :placeholder="$t('user.noCardAcc')" />
        </u-form-item>
        <u-form-item :label="$t('user.cardPass')">
          <u-input
            v-model="form.cardpwd"
            :placeholder="$t('user.noCardPass')"
          />
        </u-form-item>
      </u-form>
    </view>

    <view class="submit-bt" @click="onSubmit">{{ $t("integral.change") }}</view>
  </view>
  <Shenhe v-else-if="shenheStatus == 1"></Shenhe>
</template>

<script>
import Shenhe from "@/components/shenhe/shenhe";
export default {
  components: { Shenhe },
  data() {
    return {
      form: {
        account: "",
        cardpwd: "",
      },
    };
  },
  methods: {
    onSubmit() {
      try {
        if (!this.form.account.length)
          return this.$utils.toast(this.$t("user.noAcc"));
        if (!this.form.cardpwd.length)
          return this.$utils.toast(this.$t("user.noPass"));

        this.$utils.showModal(
          "提示",
          "是否兑换？",
          true,
          () => {
            this.$allrequest.coupon.verifyAdd(this.form).then((res) => {
              if (res.code === 0 && res.data > 0) {
                this.$allrequest.coupon
                  .verifyExchange({ sale_id: res.data })
                  .then((exchange_res) => {
                    if (exchange_res.code === 0) {
                      this.$utils.showModal(
                        "提示",
                        "充值兑换成功,请到余额里查看",
                        false,
                        () => {
                          uni.navigateBack({
                            delta: 1,
                          });
                        }
                      );
                    }
                  });
              }
            });
          },
          () => {}
        );
        // this.$utils.toast(res.msg);
      } catch (error) {
        // this.$utils.toast(error || error.msg);
      }
    },
  },

  onLoad(){
    this.$utils.isLogin()
  }
};
</script>

<style lang="scss">
.add-card {
  width: 100%;
  background: #f2f2f2;
  min-height: 100vh;
  .form-section {
    width: 100%;
    background-color: #ffffff;
    padding-left: 24rpx;
    /deep/.u-form-item {
      padding: 18rpx 0 !important;
      .u-form-item--left__content__label {
        justify-content: flex-start !important;
      }
    }
  }
}
.submit-bt {
  margin: 80rpx auto 0;
  width: 90.4vw;
  height: 88rpx;
  line-height: 88rpx;
  text-align: center;
  background: #f0250e;
  border-radius: 120rpx;
  font-size: 32rpx;
  color: #ffffff;
}
</style>
